package com.ztgf.commodity.api.client;

import com.ztgf.commodity.models.dto.CommodityLabelDTO;
import com.ztgf.commodity.models.service.ICommodityLabelService;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/commodityLabelApi")
@Api(value = "commodityLabelApiController", tags = "商品标签表Api接口")
public class CommodityLabelApiController {

    @DubboReference
    private ICommodityLabelService commodityLabelService;

    @PostMapping("/queryCategoryLabel")
    @ApiOperation(value = "根据类目id获取类目标签", notes = "根据类目id获取类目标签")
    public Result queryCategoryLabel(Long categoryId) {
        List<CommodityLabelDTO> list = commodityLabelService.queryCategoryLabel(categoryId);
        return new Result<>(list);
    }

    @PostMapping("/queryLabel")
    @ApiOperation(value = "根据类目id和品牌id获取标签信息", notes = "根据类目id和品牌id获取标签信息")
    public Result queryLabel(Long categoryId, Long brandId) {
        if (categoryId == null || brandId == null) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            List<CommodityLabelDTO> list = commodityLabelService.queryLabel(categoryId, brandId);
            return new Result<>(list);
        }
    }
}
